<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>这是一个注册页面</title>
    <!-- 样式区域 -->
    <style>
        /* 消除默认样式的干扰 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            line-height: 1.5;
            font-family: sans-serif;
            height: 100vh;
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            /* 可以根据需要更改字体 */
        }

        h1,
        h2,
        h3,
        h4,
        h5,
        h6 {
            font-weight: normal;
            /* 去掉默认的粗体 */
        }

        ul,
        ol {
            list-style: none;
            /* 去掉列表项的默认样式 */
        }

        a {
            text-decoration: none;
            /* 去掉链接的下划线 */
            color: inherit;
            /* 继承父元素的颜色 */
        }

        img {
            max-width: 100%;
            /* 确保图片不会超出容器 */
            height: auto;
            /* 保持比例 */
        }

        /* 正式样式区域 */
        /* 容器盒子 */
        .container {

            height: 100vh;
            width: 60%;
            background-color: #f5f5f5;
        }

        /* 头部显示区域 */
        .header {
            height: 20vh;
            width: 100%;
            /* background-color: orange; */
            /* //添加背景图 */
            /* background-image: url('./header.jpg'); */
            background-image: url('./head.jpg');
            background-size: 100% 100%;
            /* background-position: center; */
        }

        /* 中间显示区域 */
        .center {
            height: 70vh;
            width: 100%;
            background-color: pink;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        /* 底部区域 */
        .footer {
            height: 10vh;
            width: 100%;
            background-color: skyblue;
        }

        .foot p {
            font-size: 1rem;
            /* 或者使用其他大小 */
            color: white;
            /* 文字颜色，可以根据背景色进行调整 */
            padding-top: 4em;
            /* 上边距，用来控制文字距离顶部的距离 */
            text-align: center;
            /* 居中文本 */
        }

        .td_left {
            width: 100px;
            height: 45px;
            text-align: right;
        }

        .td_left {
            width: 100px;
            height: 45px;
            text-align: right;
        }

        .td_right {
            padding-left: 50px;
        }

        #region,
        #address,
        #education,
        #username,
        #userid,
        #repassword,
        #password,
        #email,
        #name,
        #tel,
        #birthday,
        #checkcode {
            width: 251px;
            height: 32px;
            border: 1px solid #A6A6A6;
            border-radius: 5px;
            padding-left: 10px;
        }

        #checkcode {
            width: 110px;
        }

        #img_check {
            height: 32px;
            vertical-align: middle;
        }


        #btn_sub,
        #btn_reset {
            width: 100px;
            height: 40px;
            background-color: #FFD026;
            border: 1px solid #FFD026;
            float: left;
            margin-left: 20%;
        }


        .error {
            color: red;
        }

        #td_sub {
            padding-left: 150px;
        }
    </style>
    <!--表单逻辑处理区域 -->
    <script>
        window.onload = function () {
            // window.onload 页面加载完成之后执行   
            document.getElementById("form").onsubmit = function () {
                return checkUsername() && checkPassword();
            };
            // 对用户ID和用户名、口令不符合条件及时判断
            document.getElementById("userid").onblur = checkUserID;
            document.getElementById("username").onblur = checkUsername;
            // 在输入框失去焦点时触发验证
            document.getElementById("password").onblur = checkPassword;
            document.getElementById("repassword").onblur = checkPassword;
        };

        // 验证用户ID
        function checkUserID() {
            var userID = document.getElementById("userid").value;
            var reg_userid = /^\w{6,8}$/; // 正则表达式匹配6到8位的字母数字字符或下划线
            var flag = reg_userid.test(userID);
            console.log(flag);
            var s_userid = document.getElementById("s_userid");

            if (flag) {
                s_userid.innerHTML = "<img width='35' height='25' src='./gou.png'/>";
                s_userid.className = 'valid'; // 可选：改变类名以更改样式
            } else {
                s_userid.innerHTML = "用户ID格式有误";
                s_userid.className = 'error'; // 可选：保持错误提示的样式类名
            }

            return flag;
        }
        // 验证用户名
        function checkUsername() {
            var username = document.getElementById("username").value;
            var reg_username = /^\w{6,12}$/;
            var flag = reg_username.test(username);
            var s_username = document.getElementById("s_username");
            if (flag) {
                s_username.innerHTML = "<img width='35' height='25' src='./gou.png'/>";
            }
            else {
                s_username.innerHTML = "用户名格式有误";
            } return flag;
        }

        // 验证口令密码
        function checkPassword() {
            var password = document.getElementById("password").value;
            var repassword = document.getElementById("repassword").value;
            var userid = document.getElementById("userid").value;
            var reg_password = /^\S{6,8}$/; // 正则表达式匹配6到8位的非空白字符
            var flag = reg_password.test(password);
            var s_password = document.getElementById("s_password");
            var s_repassword = document.getElementById("s_repassword");

            // 清除之前的错误信息
            s_password.innerHTML = '';
            s_repassword.innerHTML = '';

            if (!flag) {
                s_password.innerHTML = "口令格式有误（6-8位，不能包含空格）";
                return false;
            } else if (password !== repassword) {
                s_repassword.innerHTML = "两次输入的口令不一致";
                return false;
            } else if (password === userid) {
                s_password.innerHTML = "口令不能与用户ID相同";
                return false;
            }

            // 如果没有错误，则显示正确提示
            s_password.innerHTML = "<img width='35' height='25' src='./gou.png'/>";
            s_repassword.innerHTML = "<img width='35' height='25' src='./gou.png'/>";
            return true;
        }
    </script>
</head>

<body>
    <div class="container">
        <div class="header"></div>
        <!-- 中部table区域 -->
        <div class="center">
            <div class="rg_form">
                <form action="#" id="form" method="get">
                    <table>
                        <!-- 用户ID -->
                        <tr>
                            <td class="td_left"><label for="userid">用户ID</label></td>
                            <td class="td_right"> <input type="text" name="userid" id="userid" placeholder="请输入用户ID">
                                <span id="s_userid" class="error">6-8位</span>
                            </td>
                        </tr>
                        <!-- 用户名 -->
                        <tr>
                            <td class="td_left"><label for="username">用户名</label></td>
                            <td class="td_right"> <input type="text" name="username" id="username" placeholder="请输入用户名">
                                <span id="s_username" class="error">2-10位</span>
                            </td>
                        </tr>
                        <!-- 口令密码-->
                        <tr>
                            <td class="td_left"><label for="password">口令</label></td>
                            <td class="td_right"> <input type="password" name="password" id="password"
                                    placeholder="请输入口令"> <span id="s_password" class="error">6-8位，不能与用户ID相同</span> </td>
                        </tr>
                        <!-- 再次输入口令密码-->
                        <tr>
                            <td class="td_left"><label for="repassword">确认口令</label></td>
                            <td class="td_right"> <input type="password" name="repassword" id="repassword"
                                    placeholder="请再次输入口令"> <span id="s_repassword" class="error">与口令相同</span> </td>
                        </tr>
                        <!-- 生日 -->
                        <tr>
                            <td class="td_left"><label for="birthday">出生日期</label>
                            </td>
                            <td class="td_right"><input type="date" name="birthday" id="birthday" placeholder="请输入出生日期">
                                <span id="s_birthday" class="error">格式为：yyyy-mm-dd</span>
                            </td>
                            </td>
                        </tr>

                        <!-- 学历 -->
                        <tr>
                            <td class="td_left"><label for="education">学历:</label></td>
                            <td class="td_right">
                                <input type="radio" name="education" value="专科" id="education1"> 专科
                                <input type="radio" name="education" value="本科" id="education2"> 本科
                                <input type="radio" name="education" value="硕士研究生" id="education3"> 硕士研究生
                                <input type="radio" name="education" value="博士研究生" id="education4"> 博士研究生
                                <input type="radio" name="education" value="其他" id="education5"> 其他
                            </td>
                        </tr>

                        <!-- 地区 -->
                        <tr>
                            <td class="td_left"><label for="region">地区:</label></td>
                            <td class="td_right">
                                <select name="region" id="region">
                                    <option value="华清">华清</option>
                                    <option value="华南">北大</option>
                                    <option value="清华">清华</option>
                                    <option value="仲大">仲大</option>
                                    <option value="师大">师大</option>
                                    <!-- 添加更多选项 -->
                                </select>
                            </td>
                        </tr>

                        <!-- 邮箱 -->
                        <tr>
                            <td class="td_left"><label for="email">Email</label></td>
                            <td class="td_right"><input type="email" name="email" id="email" placeholder="请输入邮箱"></td>
                        </tr>
                        <!-- 地址 -->
                        <!-- 地址 -->
                        <tr>
                            <td class="td_left"><label for="address">地址:</label></td>
                            <td class="td_right">
                                <input type="text" name="address" id="address" placeholder="请输入详细地址">
                            </td>
                        </tr>
                        <!-- 手机号 -->
                        <tr>
                            <td class="td_left"><label for="tel">手机号</label></td>
                            <td class="td_right"><input type="text" name="tel" id="tel" placeholder="请输入手机号">
                                <span id="s_tel" class="error">数字和连字符，例如123456-123</span>
                            </td>
                        </tr>
                        <!-- 备注 -->
                        <tr>
                            <td class="td_left"><label for="checkcode">备注</label></td>
                            <td class="td_right">
                                <!--文本区域  -->
                                <textarea name="remark" id="remark" cols="40" rows="10" placeholder="请输入"></textarea>
                            </td>
                        </tr>

                        <!-- 表单提交区域 -->
                        <td colspan="2" style="text-align: center;">
                            <input type="submit" id="btn_sub" value="注册" style="margin-right: 10px;">
                            <input type="reset" id="btn_reset" value="重置">
                        </td>
                    </table>
                </form>
            </div>
        </div>
        <div class="footer">
            <footer class="foot">
                <p>版权所有 © Tan, 联系邮箱: tancan135cn.com</p>
            </footer>
        </div>
    </div>
</body>

</html>